package com.yozinga.model;

import java.net.URL;

import android.content.Context;
import android.os.Bundle;

import com.yozinga.service.Actions;
import com.yozinga.service.ServiceHelper;


public abstract class BaseModel implements IModel{
	
	protected ServiceHelper serviceHelper;
	protected Context mContext;

	public BaseModel(Context context) {
		mContext = context;
		serviceHelper = ServiceHelper.getInstance(mContext);
	}

	// /**
	// * This should be the default method call for the model
	// *
	// * @param isManualRefresh
	// * - if true, we won't check to see if our data is older than an hour before calling the service
	// * @return
	// */
	// public abstract int getEntities(boolean isManualRefresh);

	public interface OnRequestFinishedCallback extends ServiceHelper.OnRequestFinishedListener {
	};

	/**
	 * adds listener to serviceHelper in model
	 * 
	 * @param listener
	 */
	public void addOnServiceRequestCompletedListener(final OnRequestFinishedCallback listener) {
				
		serviceHelper.addOnRequestFinishedListener(listener);
		
	}

	/**
	 * removes listener from serviceHelper in model
	 * 
	 * @param listener
	 */
	public void removeOnServiceRequestCompleteListener(final OnRequestFinishedCallback listener) {

		
		serviceHelper.removeOnRequestFinishedListener(listener);
	}

	/*public boolean isRequestInProgress(int requestID) {

		return serviceHelper.isRequestInProgress(requestID);
	}*/

//	public boolean isRequestInProgress(ArrayList<Integer> requestIDs) {
//		return serviceHelper.isRequestInProgress(requestIDs);
//	}

	/**
	 * Calls ServiceHelper.startservice with the specified inputs
	 * 
	 * @param action
	 *            - use RestActions.ACTION
	 * @param bundle
	 *            - use null if no body
	 * @param callbackListener
	 * @return requestId
	 */
	public void makeServiceCall(String url,String id,int method, Bundle requestBody,Actions action) {
	
		serviceHelper.startService(url,id,method, requestBody,action.getText());
	}

}
